<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Spec::Translator</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Spec::Translator</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/plugins/rspec/lib/spec/translator_rb.html">
                vendor/plugins/rspec/lib/spec/translator.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000368">standard_matcher?</a>&nbsp;&nbsp;
      <a href="#M000364">translate</a>&nbsp;&nbsp;
      <a href="#M000365">translate_dir</a>&nbsp;&nbsp;
      <a href="#M000366">translate_file</a>&nbsp;&nbsp;
      <a href="#M000367">translate_line</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000368" class="method-detail">
        <a name="M000368"></a>

        <div class="method-heading">
          <a href="#M000368" class="method-signature">
          <span class="method-name">standard_matcher?</span><span class="method-args">(matcher)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000368-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000368-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/translator.rb, line 88</span>
 88:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">standard_matcher?</span>(<span class="ruby-identifier">matcher</span>)
 89:       <span class="ruby-identifier">patterns</span> = [
 90:         <span class="ruby-regexp re">/^be/</span>, 
 91:         <span class="ruby-regexp re">/^be_close/</span>,
 92:         <span class="ruby-regexp re">/^eql/</span>, 
 93:         <span class="ruby-regexp re">/^equal/</span>, 
 94:         <span class="ruby-regexp re">/^has/</span>, 
 95:         <span class="ruby-regexp re">/^have/</span>, 
 96:         <span class="ruby-regexp re">/^change/</span>, 
 97:         <span class="ruby-regexp re">/^include/</span>,
 98:         <span class="ruby-regexp re">/^match/</span>, 
 99:         <span class="ruby-regexp re">/^raise_error/</span>, 
100:         <span class="ruby-regexp re">/^respond_to/</span>, 
101:         <span class="ruby-regexp re">/^redirect_to/</span>, 
102:         <span class="ruby-regexp re">/^satisfy/</span>, 
103:         <span class="ruby-regexp re">/^throw_symbol/</span>,
104:         <span class="ruby-comment cmt"># Extra ones that we use in spec_helper</span>
105:         <span class="ruby-regexp re">/^pass/</span>,
106:         <span class="ruby-regexp re">/^fail/</span>,
107:         <span class="ruby-regexp re">/^fail_with/</span>,
108:       ]
109:       <span class="ruby-identifier">matched</span> = <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">detect</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span> <span class="ruby-identifier">matcher</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">p</span> }
110:       <span class="ruby-operator">!</span><span class="ruby-identifier">matched</span>.<span class="ruby-identifier">nil?</span>
111:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000364" class="method-detail">
        <a name="M000364"></a>

        <div class="method-heading">
          <a href="#M000364" class="method-signature">
          <span class="method-name">translate</span><span class="method-args">(from, to)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000364-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000364-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/translator.rb, line 5</span>
 5:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">translate</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>)
 6:       <span class="ruby-identifier">from</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">from</span>)
 7:       <span class="ruby-identifier">to</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">to</span>)
 8:       <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">from</span>)
 9:         <span class="ruby-identifier">translate_dir</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>)
10:       <span class="ruby-keyword kw">elsif</span>(<span class="ruby-identifier">from</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/\.rb$/</span>)
11:         <span class="ruby-identifier">translate_file</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>)
12:       <span class="ruby-keyword kw">end</span>
13:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000365" class="method-detail">
        <a name="M000365"></a>

        <div class="method-heading">
          <a href="#M000365" class="method-signature">
          <span class="method-name">translate_dir</span><span class="method-args">(from, to)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000365-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000365-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/translator.rb, line 15</span>
15:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">translate_dir</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>)
16:       <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">mkdir_p</span>(<span class="ruby-identifier">to</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">to</span>)
17:       <span class="ruby-constant">Dir</span>[<span class="ruby-node">&quot;#{from}/*&quot;</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sub_from</span><span class="ruby-operator">|</span>
18:         <span class="ruby-identifier">path</span> = <span class="ruby-identifier">sub_from</span>[<span class="ruby-identifier">from</span>.<span class="ruby-identifier">length</span><span class="ruby-operator">+</span><span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
19:         <span class="ruby-identifier">sub_to</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">to</span>, <span class="ruby-identifier">path</span>)
20:         <span class="ruby-identifier">translate</span>(<span class="ruby-identifier">sub_from</span>, <span class="ruby-identifier">sub_to</span>)
21:       <span class="ruby-keyword kw">end</span>
22:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000366" class="method-detail">
        <a name="M000366"></a>

        <div class="method-heading">
          <a href="#M000366" class="method-signature">
          <span class="method-name">translate_file</span><span class="method-args">(from, to)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000366-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000366-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/translator.rb, line 24</span>
24:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">translate_file</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>)
25:       <span class="ruby-identifier">translation</span> = <span class="ruby-value str">&quot;&quot;</span>
26:       <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">from</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">io</span><span class="ruby-operator">|</span>
27:         <span class="ruby-identifier">io</span>.<span class="ruby-identifier">each_line</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
28:           <span class="ruby-identifier">translation</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">translate_line</span>(<span class="ruby-identifier">line</span>)
29:         <span class="ruby-keyword kw">end</span>
30:       <span class="ruby-keyword kw">end</span>
31:       <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">to</span>, <span class="ruby-value str">&quot;w&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">io</span><span class="ruby-operator">|</span>
32:         <span class="ruby-identifier">io</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">translation</span>)
33:       <span class="ruby-keyword kw">end</span>
34:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000367" class="method-detail">
        <a name="M000367"></a>

        <div class="method-heading">
          <a href="#M000367" class="method-signature">
          <span class="method-name">translate_line</span><span class="method-args">(line)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000367-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000367-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/rspec/lib/spec/translator.rb, line 36</span>
36:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">translate_line</span>(<span class="ruby-identifier">line</span>)
37:       <span class="ruby-comment cmt"># Translate deprecated mock constraints</span>
38:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/:any_args/</span>, <span class="ruby-value str">'any_args'</span>)
39:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/:anything/</span>, <span class="ruby-value str">'anything'</span>)
40:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/:boolean/</span>, <span class="ruby-value str">'boolean'</span>)
41:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/:no_args/</span>, <span class="ruby-value str">'no_args'</span>)
42:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/:numeric/</span>, <span class="ruby-value str">'an_instance_of(Numeric)'</span>)
43:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/:string/</span>, <span class="ruby-value str">'an_instance_of(String)'</span>)
44: 
45:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">line</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">line</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(should_not|should)_receive/</span>
46:       
47:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/(^\s*)context([\s*|\(]['|&quot;|A-Z])/</span>, <span class="ruby-value str">'\1describe\2'</span>)
48:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/(^\s*)specify([\s*|\(]['|&quot;|A-Z])/</span>, <span class="ruby-value str">'\1it\2'</span>)
49:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/(^\s*)context_setup(\s*[do|\{])/</span>, <span class="ruby-value str">'\1before(:all)\2'</span>)
50:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/(^\s*)context_teardown(\s*[do|\{])/</span>, <span class="ruby-value str">'\1after(:all)\2'</span>)
51:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/(^\s*)setup(\s*[do|\{])/</span>, <span class="ruby-value str">'\1before(:each)\2'</span>)
52:       <span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/(^\s*)teardown(\s*[do|\{])/</span>, <span class="ruby-value str">'\1after(:each)\2'</span>)
53:       
54:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">line</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(.*\.)(should_not|should)(?:_be)(?!_)(.*)/</span><span class="ruby-identifier">m</span>
55:         <span class="ruby-identifier">pre</span> = <span class="ruby-identifier">$1</span>
56:         <span class="ruby-identifier">should</span> = <span class="ruby-identifier">$2</span>
57:         <span class="ruby-identifier">post</span> = <span class="ruby-identifier">$3</span>
58:         <span class="ruby-identifier">be_or_equal</span> = <span class="ruby-identifier">post</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(&lt;|&gt;)/</span> <span class="ruby-operator">?</span> <span class="ruby-value str">&quot;be&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;equal&quot;</span>
59:         
60:         <span class="ruby-keyword kw">return</span> <span class="ruby-node">&quot;#{pre}#{should} #{be_or_equal}#{post}&quot;</span>
61:       <span class="ruby-keyword kw">end</span>
62:       
63:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">line</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(.*\.)(should_not|should)_(?!not)\s*(.*)/</span><span class="ruby-identifier">m</span>
64:         <span class="ruby-identifier">pre</span> = <span class="ruby-identifier">$1</span>
65:         <span class="ruby-identifier">should</span> = <span class="ruby-identifier">$2</span>
66:         <span class="ruby-identifier">post</span> = <span class="ruby-identifier">$3</span>
67:         
68:         <span class="ruby-identifier">post</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^raise/</span>, <span class="ruby-value str">'raise_error'</span>)
69:         <span class="ruby-identifier">post</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^throw/</span>, <span class="ruby-value str">'throw_symbol'</span>)
70:         
71:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">standard_matcher?</span>(<span class="ruby-identifier">post</span>)
72:           <span class="ruby-identifier">post</span> = <span class="ruby-node">&quot;be_#{post}&quot;</span>
73:         <span class="ruby-keyword kw">end</span>
74:         
75:         <span class="ruby-comment cmt"># Add parenthesis</span>
76:         <span class="ruby-identifier">post</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^(\w+)\s+([\w|\.|\,|\(.*\)|\'|\&quot;|\:|@| ]+)(\})/</span>, <span class="ruby-value str">'\1(\2)\3'</span>) <span class="ruby-comment cmt"># inside a block</span>
77:         <span class="ruby-identifier">post</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^(redirect_to)\s+(.*)/</span>, <span class="ruby-value str">'\1(\2)'</span>) <span class="ruby-comment cmt"># redirect_to, which often has http:</span>
78:         <span class="ruby-identifier">post</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^(\w+)\s+([\w|\.|\,|\(.*\)|\{.*\}|\'|\&quot;|\:|@| ]+)/</span>, <span class="ruby-value str">'\1(\2)'</span>)
79:         <span class="ruby-identifier">post</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/(\s+\))/</span>, <span class="ruby-value str">')'</span>)
80:         <span class="ruby-identifier">post</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/\)\}/</span>, <span class="ruby-value str">') }'</span>)
81:         <span class="ruby-identifier">post</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^(\w+)\s+(\/.*\/)/</span>, <span class="ruby-value str">'\1(\2)'</span>) <span class="ruby-comment cmt">#regexps</span>
82:         <span class="ruby-identifier">line</span> = <span class="ruby-node">&quot;#{pre}#{should} #{post}&quot;</span>
83:       <span class="ruby-keyword kw">end</span>
84: 
85:       <span class="ruby-identifier">line</span>
86:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>